package ch7.ex1;

public class Marek2 {
	public static void main(String[] args) {
		Person p1 = new Person();
		Person p2 = new Person();
		Person p3 = new Person();

		Integer maxw = 0;
		Integer poz = 0;
		//Person[] persons={};
		Person[] persons = { new Person(), new Person(), new Person() };
		persons[0].name = "jas";
		persons[0].age = 53;
		persons[1].name = "bart";
		persons[1].age = 23;
		persons[2].name = "ola";
		persons[2].age = 40;

		
		for (Integer x = 0; x < persons.length; x++)
			if (persons[x].age > maxw) {
				maxw = persons[x].age;
				poz = x;
			}
		System.out.println("osoba " + persons[poz].name + " "
				+ persons[poz].age);

		p1.name = "kris";

		p1.age = 31;
		p2.name = "Mark";
		p2.age = 37;

		p3.name = "john";
		p3.age = 50;
		{
			Person theoldest = new Person();
			theoldest.age = 0;
			for (Person person : persons) {
				// if (person.age > theoldest.age)
				// theoldest = person;
				theoldest = (person.age > theoldest.age) ? person : theoldest;
			}
			System.out.println("111 " + theoldest.name + " " + theoldest.age);
		}
		Person theoldest = findthe(persons);
		System.out.println("222 " + theoldest.name + " " + theoldest.age);

	}

	static Person findthe(Person[] persons) {
		Person theoldest = new Person();
		theoldest.age = 0;
		for (Person person : persons) {
			// if (person.age > theoldest.age)
			// theoldest = person;
			theoldest = (person.age > theoldest.age) ? person : theoldest;
		}
		return theoldest;
	}
}
